import { useEffect, useState } from 'react';
import Modals from '@/components/modals/Modals';
import { Input } from '@/components/eai-design';

interface EditQuestionModalProps {
  open: boolean;
  value: string;
  onOk: (newValue: string) => void;
  onCancel: () => void;
}

export default function EditQuestionModal({ open, value, onOk, onCancel }: EditQuestionModalProps) {
  const [inputValue, setInputValue] = useState(value);

  // 保证每次打开弹窗都重置输入内容
  // 如果你用的是 v5 antd，可以用 useEffect 监听 open+value
  useEffect(() => {
    setInputValue(value);
  }, [open, value]);

  return (
    <Modals
      open={open}
      onCancel={onCancel}
      title="编辑问题"
      width={480}
      onOk={() => {
        onOk(inputValue);
      }}
    >
      <Input
        value={inputValue}
        onChange={(e) => setInputValue(e.target.value)}
        placeholder="请输入问题"
        className="!h-10 !rounded-full !text-base"
        style={{
          border: '1px solid #F0F0F0',
        }}
        maxLength={100}
      />
    </Modals>
  );
}
